<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%><!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
	.tree-node {padding:0;}
	img {
		height:50px;
		width:50px;
	}
</style>
  </head>
  <body>
  	<div class="easyui-layout" data-options="fit:true">
		<div data-options="region:'north',border:false">
			<fieldset>
    		<legend>过滤条件</legend>
    		<table style="width:100%">
    			<tr>条件查询</tr>
    		</table>
  		</fieldset>
		</div>
  		<div data-options="region:'center',border:false" style="padding-bottom: 33px">
  			<div class="easyui-layout" data-options="fit:true">
                <div data-options="region:'north',split:true,title:'圈子信息'" style="height:300px">
					<table id="group_grid"></table>              
                </div>
                <div data-options="region:'center',title:'话题信息' " style="padding-bottom: 33px">
                	<div id="topic_grid_toolbar" class="toolbar"></div>
                	<table id="topic_grid"></table>
                </div>
            </div>
		</div>
		
	</div>
	<script>
		$(function(){
			$('#topic_grid_toolbar').toolbar({buttons:[
	           	{name:'add',iconCls:'icon-add',text:'添加话题'},
	      	],handler:handler});
			
			$('#group_grid').datagrid({
		    	url:'/group/info/page',
	    		pagination:true,
	    		singleSelect:true,
	    		rownumbers:false,
	    		striped:true,
	    		fit:true,
	    		fitColumns:true,
	    		toorbar:'#toolbar_group',
	    		columns:[[
	    			{field:'ck',checkbox:true},
	    			{field:'id',title:'编号'},
	    			{field:'groupName',title:'名称'},
	    			{field:'groupNote',title:'备注'},
	        		{field:'createdDt',title:'创建时间'},
	        		{field:'updatedDt',title:'更新时间'},
	    		]],
	    		onSelect:loadTopic
			 });
			
			//加载成员信息
			function loadTopic(index,row){
				var param = {};
		    	param.groupId = row.id;
		    	$('#topic_grid').datagrid({ 
		    		queryParams: param,
		    		url:"findByGrouoIdToPage"
		    	}); 
			}
			
			$('#topic_grid').datagrid({
		    	//url:'',
	    		pagination:true,
	    		singleSelect:true,
	    		rownumbers:false,
	    		striped:true,
	    		fit:true,
	    		fitColumns:true,
	    		toorbar:'#toolbar_articleTable',
	    		columns:[[
	    			{field:'id',title:'编号'},
	    			{field:'articleTitle',title:'文章标题'},
	        		{field:'userName',title:'作者'},
	        		{field:'articleType',title:'类型',formatter:function(v,r,i){
	        			var type ="";
	        			if(r.articleType == "1"){type ="文章"}else if(r.articleType == "3"){type ="音频"}else if(r.articleType == "5"){type="视频"}else if(r.articleType == "7"){type="话题pk"}
	        			return type;
	        		}},
	        		{field:'countView',title:'浏览量'},
	        		{field:'countPraise',title:'点赞量'},
	        		{field:'countShare',title:'分享量'},
	        		{field:'countCollect',title:'收藏量'},
	        		{field:'enabled',title:'删除标记',formatter:function(v,r,i){
	        			var show = '删除';
	        			if(r.enabled){
	        				show = '正常';
	        			}
	        			return show;
	        		}},
	        		{field:'createdDt',title:'创建时间'},
	        		{field:'-',title:'操作',align:'center',formatter:function(v,r,i){
	        			var action = '<a href="#" onclick="toEdit('+r.id+');">编辑</a>&nbsp;&nbsp;';
	        			if(r.enabled){
	        				action = action+'<a href="#" onclick ="updateEnabled('+r.id+');">禁用</a>';
	        			}else{
	        				action = action+'<a href="#" onclick="updateEnabled('+r.id+');">启用</a>';
	        				
	        			}
	        			action = action+'&nbsp;&nbsp;<a href="#">查看</a>';
	        			
						return action;
					}}
	    		]],
	    		view: detailview,
	    	    detailFormatter: function(rowIndex, rowData){
	    	        return '<table><tr>' +
	    	                '<td rowspan=2 style="border:0,height:50px;">'+rowData.articleContent+'</td>' +
	    	                '</tr></table>';
	    	    }
			 });
			
		});
		
		function handler() {
			if(this.name == 'search') return toSearch();
			var item = $('#group_grid').datagrid('getSelected');
			if(!item) return;
			if(this.name == 'add') return toAdd(item);
			switch(this.name) {
			case 'addSub': add(item);break;
			case 'edit': toEdit(item);break;
			}
		}
		function toAdd(item){
			show({code:'topic_grid_add',title:'编辑话题信息',iconCls:'icon-edit',uri:'addTopic?groupId='+item.id,width:800,height:600,
				options : {
					success : function(data) { 
						$('#topic_grid').datagrid('reload'); 
					}
				}
			});
		}
		function toEdit(id) {
			show({code:'topic_grid_edit',title:'编辑话题信息',iconCls:'icon-edit',uri:'edit?id='+id,width:800,height:600,
				options : {
					success : function(data) { 
						$('#topic_grid').datagrid('reload'); 
					}
				}
			});
		}
		
		function toDel(id) {
			var item = $('#group_grid').datagrid('getSelected');
			var param = {};
	    	param.groupId = item.id;
	    	param.userId = id;
			$confirm('您确定要删除该成员吗？',function() {
				$.post('deleteBygroupIdAndUserId',param,function(r) {
					if(r.code <= 0) return $error(r.msg);
					$('#topic_grid').datagrid('reload');
					$prompt('删除成功');
				},'json');
			});
		}
		
		function updateEnabled(id){
			var parms = {};
			parms.id = id;
			parms.enabled = true;
			$.post('updateEnabled',parms,function(r){
				if(r.code>0){
					$('#topic_grid').datagrid('reload'); 
				};
			},'json');
		}
		
	</script>
  </body>
</html>